

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

import org.mortbay.util.ajax.JSON;

import xfireservice.service.IntelligentTerminalLocator;
import xfireservice.service.IntelligentTerminalPortType;


public class Client {
	
	 private static final String userID = "admin.android.dy";
     private static final String mykey = "B9C507A748246EF370CF165C71DC6706";
     private static URL endpoint;
     static {
    	 try {
			endpoint = new URL("http://127.0.0.1:8080/sdjy/xfireservice/IntelligentTerminal");  
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}  
     }
	 public static void main(String args[]) throws MalformedURLException  {  
		 getShenbaoInfo();
		 getShenbaoForm();
		//updateReprotPrint();
		  
	 }  
	 public static void getShenbaoInfo() {
		 try {  
	          //客户端调用
		      IntelligentTerminalLocator seWebServiceLocator = new IntelligentTerminalLocator();  
	          IntelligentTerminalPortType seWebServiceHttpPort = seWebServiceLocator.getIntelligentTerminalHttpPort(endpoint);  
		     
	          String code="20141110015";
		      StringBuilder valueStr = new StringBuilder("userID=");
	          valueStr.append(userID);
	          valueStr.append("&code=").append(code.trim());
	          valueStr.append("&key=").append(mykey);
	          String sign = enCodeMd5(valueStr.toString().toLowerCase()).toUpperCase();
	          String str = seWebServiceHttpPort.getShenbaoInfo(code, sign);
		      System.out.println(str);
		      
		    }catch (Exception e) {  
	    }  
	 }
	 public static void getShenbaoForm() {
		 try {  
	          //客户端调用
		      IntelligentTerminalLocator seWebServiceLocator = new IntelligentTerminalLocator();  
	          IntelligentTerminalPortType seWebServiceHttpPort = seWebServiceLocator.getIntelligentTerminalHttpPort(endpoint);  
		     
		      StringBuilder valueStr = new StringBuilder("userID=");
	          valueStr.append(userID);
	          Map<String,String>map=new HashMap<String,String>();
	          map.put("sbdw", "东营市荣军医院");
//	          map.put("bjrq1", "2014-12-31");
//	          map.put("bjrq2", "2015-12-31");
//	          map.put("lxr", "岳");
//	          map.put("lxdh", "13376476345");
	          String condition=JSON.toString(map);
	          valueStr.append("&condition=").append(condition);
	          valueStr.append("&key=").append(mykey);
	          String sign = enCodeMd5(valueStr.toString().toLowerCase()).toUpperCase();
	          String str = seWebServiceHttpPort.getShenbaoForm(condition, sign);
		      System.out.println(str);
		      
		    }catch (Exception e) {  
	    }  
	 }
	 public static void updateReprotPrint() {
		 try {  
	          //客户端调用
		      IntelligentTerminalLocator seWebServiceLocator = new IntelligentTerminalLocator();  
	          IntelligentTerminalPortType seWebServiceHttpPort = seWebServiceLocator.getIntelligentTerminalHttpPort(endpoint);  
		     
		      StringBuilder valueStr = new StringBuilder("userID=");
	          valueStr.append(userID);
	          String id="50729516";
	          valueStr.append("&id=").append(id);
	          valueStr.append("&key=").append(mykey);
	          String sign = enCodeMd5(valueStr.toString().toLowerCase()).toUpperCase();
	          String str = seWebServiceHttpPort.updateReportPrint(id, sign);
		      System.out.println(str);
		      
		    }catch (Exception e) {  
	    }  
	 }
	  public static String enCodeMd5(String srcStr) {
	        String res = "";
	        try {
	            MessageDigest md5 = MessageDigest.getInstance("MD5");
	            md5.update(srcStr.getBytes("UTF-8"));
	            byte[] m = md5.digest();//加密
	            StringBuffer buf = new StringBuffer();
	            for (int i = 0; i < m.length; i++) {
	                int x = m[i] & 0xff;
	                if (x < 0xf) {
	                    buf.append("0");
	                }
	                buf.append(Integer.toHexString(x));
	            }
	            res = buf.toString();
	        } catch (NoSuchAlgorithmException e) {
	            e.printStackTrace();
	        } catch (UnsupportedEncodingException e) {
	            e.printStackTrace();
	        }
	        return res;
	    }

}
